<?php
/**
 * FastApp.
 * 8/21/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateMarketingTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('marketing_gradient', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('梯度消费奖励');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->addColumn('string', 'remark', ['length' => 255, 'comment' => '备注'])->nullable();
            $table->char('event', 64)->nullable()->comment('事件');
            $table->tinyInteger('status')->comment('启用0否1是')->unsigned()->default(0);
            $table->integer('account_type')->comment('入口类型')->unsigned()->default(1);
            $table->char('code', 32)->comment('标识');
            $table->json('object_id')->nullable()->comment('数据id');
            $table->json('config')->nullable()->comment('配置');
            $table->index('code');
        });
        Schema::create('marketing_gradient_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('奖励完成列表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->bigInteger('gradient_id')->comment('任务id')->unsigned();
            $table->decimal('amount', 11)->comment('达标')->unsigned();
            $table->decimal('refunded', 11)->comment('奖励')->unsigned();
            $table->smallInteger('idx')->comment('索引')->unsigned();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->date('date')->comment('日期');
            $table->timestamp('get_at')->nullable()->comment('领取时间');
            $table->unique(['user_id', 'gradient_id', 'amount']);
        });
        Schema::create('marketing_task', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('任务表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->tinyInteger('status')->comment('启用0否1是')->unsigned()->default(0);
            $table->json('name')->nullable()->comment('任务名称');
            $table->json('title')->nullable()->comment('标题');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->decimal('amount', 11)->comment('达标')->unsigned()->default(0);
            $table->decimal('refunded', 11)->comment('奖励')->unsigned()->default(0);
            $table->char('code', 32)->comment('code');
            $table->char('event', 32)->comment('事件名称');
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->tinyInteger('type')->comment('1仅一次2每日3每周')->unsigned()->default(1);
            $table->tinyInteger('accumulation')->comment('累计0否1是')->unsigned()->default(0);
            $table->integer('account_type')->comment('入口类型')->unsigned()->default(1);
            $table->index('code');
        });
        Schema::create('marketing_task_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('任务完成表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->bigInteger('task_id')->comment('任务id')->unsigned();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->date('date')->comment('日期');
            $table->timestamp('get_at')->nullable()->comment('领取时间');
            $table->unique(['user_id', 'task_id', 'date']);
        });
        Schema::create('marketing_blind_box', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('盲盒');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->timestamps();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('name')->nullable();
            $table->json('title')->nullable()->comment('标题');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->char('code', 32)->comment('code');
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(100);
            $table->tinyInteger('type')->nullable()->comment('1奖金2奖品')->unsigned();
            $table->decimal('pool', 11)->nullable()->comment('奖池金额')->default(0);
            $table->decimal('price', 11)->comment('价格');
            $table->json('config')->nullable()->comment('配置');
            $table->index('code');
        });
        Schema::create('marketing_blind_box_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('开盒记录');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('box_id')->comment('盒子id')->unsigned();
            $table->tinyInteger('num')->comment('数量')->unsigned();
            $table->decimal('amount', 11)->comment('金额')->unsigned();
            $table->tinyInteger('type')->comment('1奖金2奖品')->unsigned();
            $table->json('refunded')->comment('奖励')->nullable();
            $table->index('user_id');
            $table->index('box_id');
        });
        Schema::create('marketing_lotto', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('彩票');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->char('code', 32)->nullable()->comment('code');
            $table->tinyInteger('groups')->nullable()->comment('号码组数')->unsigned()->default(7);
            $table->integer('periods')->nullable()->comment('期数')->unsigned()->default(0);
            $table->decimal('price', 6)->nullable()->comment('单注价格')->unsigned()->default(0);
            $table->decimal('pool', 11)->nullable()->comment('奖池')->unsigned()->default(0);
            $table->tinyInteger('open_type')->nullable()->comment('1分2时3天')->unsigned()->default(1);
            $table->tinyInteger('open_time')->nullable()->comment('周期时间')->unsigned()->default(0);
            $table->tinyInteger('open_hour')->nullable()->comment('type为3填写小时')->unsigned()->default(0);
            $table->tinyInteger('status')->nullable()->comment('开启0否1是')->unsigned()->default(1);
            $table->smallInteger('people_num')->nullable()->comment('满人开')->unsigned()->default(0);
            $table->integer('open_at')->nullable()->comment('开奖时间')->unsigned()->default(0);
            $table->json('name')->nullable();
            $table->json('content')->nullable();
            $table->json('config')->nullable();
            $table->unique('code');
        });
        Schema::create('marketing_lotto_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('彩票记录');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('lotto_id')->comment('彩票id')->unsigned();
            $table->char('no', 32)->comment('号码');
            $table->smallInteger('num')->comment('注数')->unsigned()->default(0);
            $table->smallInteger('periods')->comment('期数')->unsigned();
            $table->tinyInteger('level')->comment('中奖等级')->unsigned()->default(0);
            $table->tinyInteger('status')->comment('领取0否1是')->unsigned()->default(0);
            $table->decimal('amount', 11)->comment('中奖金额')->default(0);
        });
        Schema::create('marketing_lotto_open', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('开奖记录');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('lotto_id')->comment('彩票id')->unsigned();
            $table->smallInteger('periods')->comment('期数')->unsigned();
            $table->char('no', 32)->comment('开奖号码');
        });
        Schema::create('marketing_cash_prize', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('现金奖励');
            $table->bigIncrements('id')->comment('主键');
            $table->integer('account_type')->comment('入口类型')->unsigned()->default(1);
            $table->char('symbol', 8)->comment('币种');
            $table->char('code', 32)->nullable()->comment('调用码');
            $table->char('no', 16)->comment('领取码');
            $table->integer('num')->comment('限领数量')->unsigned()->default(0);
            $table->tinyInteger('status')->comment('完成0否1是')->unsigned()->default(0);
            $table->date('start_at')->nullable()->comment('开始时间');
            $table->date('end_at')->nullable()->comment('结束时间');
            $table->decimal('min', 11)->default(0);
            $table->decimal('max', 11)->default(0);
            $table->json('config')->nullable();
            $table->timestamps();
            $table->unique('no');
            $table->unique(['code', 'account_type']);
        });
        Schema::create('marketing_cash_prize_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('现金奖励领取记录');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned()->default(0);
            $table->bigInteger('prize_id')->comment('奖励id')->unsigned()->default(0);
            $table->tinyInteger('status')->comment('领取0否1是')->unsigned()->default(0);
            $table->decimal('amount', 11)->comment('金额')->default(0);
            $table->timestamps();
            $table->index('user_id');
            $table->index('prize_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('marketing_gradient');
        Schema::dropIfExists('marketing_gradient_log');
        Schema::dropIfExists('marketing_task');
        Schema::dropIfExists('marketing_task_log');
        Schema::dropIfExists('marketing_blind_box');
        Schema::dropIfExists('marketing_blind_box_log');
        Schema::dropIfExists('marketing_lotto');
        Schema::dropIfExists('marketing_lotto_log');
        Schema::dropIfExists('marketing_lotto_open');
        Schema::dropIfExists('marketing_cash_prize');
        Schema::dropIfExists('marketing_cash_prize_log');
    }
}
